<%@ page language="java" contentType="text/html;charset=UTF-8"%>
<%@ page import="com.gouwudai.gobbs.vo.UserLoginVO,com.gouwudai.gobbs.pojo.TbbsUserInfo" %>
<%@ include file="../common/common.jsp" %>
<%
UserLoginVO userLogin = (UserLoginVO)session.getAttribute("USER_LOGIN");

if(userLogin==null||userLogin.getUserId()==null||userLogin.getUserId().intValue()==0)	//如果用户尚未登陆，验证是否在COOKIE中有历史记录
{
	try
	{	
		IUserService userService = (IUserService)BeanManager.getBean("userService");
		userLogin = userService.userLogin(request.getCookies(),request.getRemoteAddr());	
		session.setAttribute("USER_LOGIN",userLogin);		
	}
	catch(NotLoginException e)
	{
		
	}
}
%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><%=SYSTITLE%> - 用户登录</title>
<meta name="Keywords" content="<%=SYSMETAKEY%>" />
<meta name="Description" content="<%=SYSMETADESC%>" />
<%@ include file="../common/meta.inc" %>
<STYLE type="text/css" media="screen">
@import url(css/defaultStyle.css);
</STYLE>
</head>
<body style="background-color:transparent" >
<script language="javascript" type="text/javascript" src="scripts/userLogin.js"></script>
<script language="javascript" src="${pageContext.request.contextPath}/scripts/prototype.js"></script>
<script language="javascript" src="${pageContext.request.contextPath}/scripts/buffalo/buffalo.js"></script>
<script language="javascript" type="text/javascript">
var END_POINT="${pageContext.request.contextPath}/buffalo";
var buffalo = new Buffalo(END_POINT,false);
function doSubmit() 
{	
	form = document.theform;
	if(!validateUserLoginForm(form))
		return false;		
		
    var obj = {};    
    
	obj[Buffalo.BOCLASS] = "java.util.HashMap";

	var loginId = trim($F('loginId'));
	var password = $F('password');
	var loginIp = "<%=request.getRemoteAddr()%>";
	buffalo.remoteCall("userServiceAjaxService.userLoginAjax",[loginId,password,loginIp], function(reply) 
    {
       	var ret = reply.getResult();
       	var params = parseAjaxReturn(ret);			
       	if(params=="error")
       	{
       		sl_alert(ret);       		
       	}
       	else
       	{ 
       		location.reload();
        }  
	       	    	
    });	  
}
</script>
<DIV class="line"></DIV>
<%
if(userLogin==null||userLogin.getUserId()==null||userLogin.getUserId().intValue()==0) {
%>
<form name="theform" id=""theform"" method="post" target="_self" onSubmit="doSubmit();return false;">
	欢迎诸君莅临：<%=SYSNAME%> <br />
	<a href="user_reg.jsp" target="_parent">如果你还没注册，请先注册，享受更多服务＞＞</a>
	<br><strong>用户</strong>
	<input name="loginId" type="text" id="loginId"  maxlength="50" style="width:120px;" onkeydown="javascript:nextKeyPress(this);"/>
	<br><strong>密码</strong>
	<input name="password" type="password" id="password" value="" maxlength="50" style="width:120px;"/>&nbsp;&nbsp;&nbsp;
	<button name="btnSubmit" type="submit" class="btn" id="btnSubmit">登陆</button>	
</form>
<%
	} else {
	IUserService userService = (IUserService)BeanManager.getBean("userService");
	TbbsUserInfo tbbsUserInfo = (TbbsUserInfo)userService.load(userLogin.getUserId());
%>
	<strong><%=tbbsUserInfo.getUserName() %></strong>
	&nbsp;<span class="style1">欢迎莅临&nbsp;<%=SYSNAME%></span>
	<DIV class="line"></DIV>
	<strong>信誉:</strong><%=tbbsUserInfo.getUserCredit() %>
	&nbsp;&nbsp;&nbsp;&nbsp;
	<strong>积分:</strong><%=tbbsUserInfo.getUserMark() %>
	<DIV class="line"></DIV>
	<strong>金币:</strong><%=tbbsUserInfo.getUserMoney()%>
<%} %>
</body>
</html>